using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.Common;
using Domain.pe.com.workspace;
using System.Collections;
using Spring.Data.Objects;
using Common.Logging;

namespace DAO.pe.com.workspace.usuario.impl.procedure
{
    public class ObtenerFacturaProcedure : StoredProcedure
    {
        private static ILog logger = LogManager.GetLogger(typeof(ObtenerFacturaProcedure));

        public ObtenerFacturaProcedure(IDbProvider dbProvider, string procedureName)
            : base(dbProvider, procedureName)
        {    
            DeriveParameters();
            Compile();
        }
        
        public virtual Factura ejecutar(int orderid)
        {
            logger.Debug("iniciando ejecucion de procedure");
            IDictionary inParameterValues = new Hashtable();
            inParameterValues["@id"] = orderid;           
            IDictionary outParams = QueryByNamedParam(inParameterValues);
            Factura factura = new Factura();
            factura.Id = orderid;
            if (outParams["@fecha"] is DateTime)
            {
                factura.Fecha = (DateTime)outParams["@fecha"];
            }
            if (outParams["@nombreCliente"] is String)
            {
                factura.NombreCliente = (String)outParams["@nombreCliente"];
            }
            if (outParams["@total"] is int)
            {
                factura.Total = (int)outParams["@total"];
            }
            return factura;
        }
    }
}
